//导入数据库模块
const db = require('../db/db')

const Order ={

    // 添加预订单
   async addOrder(order){
        let {oid,ostate,sname,simg,uid,size,num,sprice,addres,aname,tel} = order
        let sqlStr = 'INSERT INTO `order` (oid,ostate,sname,simg,uid,size,number,sprice,addres,aname,tel) VALUES(?,?,?,?,?,?,?,?,?,?,?)'
       let data = await new Promise((resolve,reject)=>{
            db.query(sqlStr,[oid,ostate,sname,simg,uid,size,num,sprice,addres,aname,tel],(err,result)=>{
                if(err)reject(err)
                resolve(result) 
            })
        })
        return data
    },

    // 查询订单
    // async getOrder(oid){
    //     let sqlStr = 'SELECT * FROM `order` WHERE oid =?'
    //     let data = await new Promise((resolve,reject)=>{
    //         db.query(sqlStr,[oid],(err,result)=>{
    //             if(err)reject(err)
    //             resolve(result) 
    //         })
    //     })
    //     return data
    // },
    
    // 付款订单
    async payOrder(oid){
        let sqlStr = 'UPDATE `order` SET ostate = 2 WHERE oid =?'
        let data = await new Promise((resolve,reject)=>{
            db.query(sqlStr,[oid],(err,result)=>{
                if(err)reject(err)
                resolve(result) 
            })
        })
        return data
    },


}


module.exports = Order